package com.starblink.android.basic.extension.apollo

import android.net.Uri
import com.starblink.android.basic.data.model.product.ProductFWrap
import com.starblink.android.basic.data.model.product.RecommendProductF
import com.starblink.rocketreserver.fragment.CategoryF
import com.starblink.rocketreserver.fragment.MerchantWebVOF
import com.starblink.rocketreserver.fragment.ProductF

/**
 * 商户网址展示
 */
val MerchantWebVOF.websiteShow: String?
    get() {
        return try {
            Uri.parse(merchantWebUrl).host
        } catch (e: Exception) {
            null
        }
    }

val CategoryF.id2String: String
   get() = id?.toString() ?: ""

val MerchantWebVOF.hasOnSaleTag: Boolean
   get() = (cornerLabels?.indexOfFirst { it.type == 1 }?: - 1) > -1

/**
 * index 为数据中位置，用于埋点或者其他用途
 */
fun ProductF.toWrap(index: Int = 0) = ProductFWrap(this, index = index)

/**
 * index 为数据中位置，用于埋点或者其他用途
 */
fun ProductF.toRecommendWrap(index: Int = 0) = RecommendProductF(this, index = index)
